package ldk.xposed.dexreplace

import org.junit.Assert.*
import org.junit.Test
import org.xmlpull.v1.XmlPullParserFactory
import java.io.StringReader
import java.io.StringWriter

class ReplaceDexInfoTest{


    @Test
    fun testSerializerAndParser(){
        val serializer = XmlPullParserFactory.newInstance("org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer", null).newSerializer()
        val stringWriter = StringWriter()
        serializer.setOutput(stringWriter)
        serializer.startDocument("UTF-8", true)
        serializer.startTag(null, "packages")
        val origin = ReplaceDexInfo("/sdcard/dexreplace/test.dex", "com.cliff")
        origin.writeToXml(serializer)
        serializer.endTag(null, "packages")
        serializer.endDocument()
        val xmlString = stringWriter.toString()


        val parser = XmlPullParserFactory.newInstance().newPullParser()
        parser.setInput(StringReader(xmlString))
        parser.next()
        parser.next()
        val info = ReplaceDexInfo.parseReplaceDexInfo(parser)
        assertEquals(origin.dexFilePath, info.dexFilePath)
        assertEquals(origin.packageName, info.packageName)
    }
}